<?php

require_once 'models/DAL/NewsletterDAO.php';

class Application_Model_DbTable_Newsletter extends Zend_Db_Table_Abstract {

    protected $_name = 'Newsletter';
    protected $_primary = 'idNewsletter';

    public function cadastrar(Application_Model_DAO_Newsletter $object) {

        try {
            $this->getAdapter()->beginTransaction();

            $this->insert(
                    array(
                        'idNewsletter' => $object->getIdNewsletter(),
                        'codContato' => $object->getCodUsuario(),
                        'codUsuario' => $object->getCodUsuario(),
                        'emailNewsletter' => $object->getEmailNewsletter()
                    )
            );
            $this->getAdapter()->commit();
            $object->setIdNewsletter((int) $this->getAdapter()->lastInsertId());
        } catch (Zend_Db_Table_Exception $e) {
            $this->getAdapter()->rollBack();

            exit('Erro ao tentar cadastrar newsletter :: ' . $e->getMessage());
        }

        return $object;
    }

}

